package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.GoodsPurchaseMapper;
import com.itheima.pojo.GoodPurchase;
import com.itheima.pojo.GoodsPurchaseQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.service.GoodsPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
public class GoodsPurchaseServiceImpl implements GoodsPurchaseService {

    @Autowired
    private GoodsPurchaseMapper goodsPurchaseMapper;

    @Override
    public void delete(Integer id) {
        goodsPurchaseMapper.delete(id);
    }

    @Override
    public void add(GoodPurchase goodPurchase) {
        goodsPurchaseMapper.add(goodPurchase);
    }

//    @Transactional
    @Override
    public void update(GoodPurchase goodPurchase) {

        goodsPurchaseMapper.update(goodPurchase);

    }

    @Override
    public PageBean page(GoodsPurchaseQueryParam goodsPurchaseQueryParam) {
        //1. 设置分页参数
        PageHelper.startPage(goodsPurchaseQueryParam.getPage(),goodsPurchaseQueryParam.getPageSize());
        //2. 调用方法查询数据

        Page<GoodPurchase> goodPurchasesPage = goodsPurchaseMapper.list(goodsPurchaseQueryParam);
        return new PageBean(goodPurchasesPage.getTotal(),goodPurchasesPage.getResult());
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        goodsPurchaseMapper.deleteByIds(ids);
    }
}














